package com.database;

import java.sql.*;
public class DB {
	
	  String user="root";
	  String password="87596992";
	  String url = "jdbc:mysql://localhost:3306/DB";
	  Statement smt= null;
	  Connection con=null;
	  ResultSet rs= null;
	  PreparedStatement presmt=null;
	  
	  public DB() throws ClassNotFoundException
	  {
		  Class.forName("com.mysql.jdbc.Driver");		  
	  }
	  
	  public ResultSet executeQuery(String sql)
	  {
		  try{
			  	con=DriverManager.getConnection(url,user,password);
			  	smt=con.createStatement();
			  	rs=smt.executeQuery(sql);
		  }
		  catch(SQLException ex)
		  {
			  ex.printStackTrace();
		  }
		  return rs;
	  }
	  public int executeUpdate(String sql)
	  {
		  int result=0;
		  try{
			  con=DriverManager.getConnection(url,user,password);
			  smt=con.createStatement();
			  result=smt.executeUpdate(sql);
		  }catch(SQLException ex)
		  {
			  ex.printStackTrace();
		  }
		  return result;
	  }
	  public PreparedStatement insert(String sql)
	  {
		  try{
			  	con=DriverManager.getConnection(url,user,password);
			    presmt=con.prepareStatement(sql);
		  }
		  catch(SQLException ex)
		  {
			  ex.printStackTrace();
		  }
		  return presmt;
	  }
	 public void conclose()
	 {
		 
			  try{
				  con.close();
			  }
			  catch(SQLException ex)
			  {
				  ex.printStackTrace();
			  }
	 }
	 public void smtclose()
	 {
		 try{
			  smt.close();
		  }
		  catch(SQLException ex)
		  {
			  ex.printStackTrace();
		  }
	 }

	public void rsclose()
	{
		 try{
			  rs.close();
		  }
		  catch(SQLException ex)
		  {
			  ex.printStackTrace();
		  }
	}
		 
			 
}